# # 1、nc和nc间比较
# import os
#
#
# def get_file_identifiers(folder_path):
#     """提取文件夹中所有文件名的特定部分"""
#     file_identifiers = {}
#     for filename in os.listdir(folder_path):
#         if filename.endswith('.NC'):
#             try:
#                 parts = filename.split('_')
#                 identifier = '_'.join(parts[9:11])
#                 file_identifiers[filename] = identifier
#             except IndexError:
#                 print(f"文件名格式错误: {filename}")
#     return file_identifiers
#
#
# def compare_file_identifiers(folder1_identifiers, folder2_identifiers):
#     """比较两个文件夹的文件名特定部分"""
#     folder1_unique = []
#     folder2_unique = []
#
#     for filename, identifier in folder1_identifiers.items():
#         if identifier not in folder2_identifiers.values():
#             folder1_unique.append(filename)
#
#     for filename, identifier in folder2_identifiers.items():
#         if identifier not in folder1_identifiers.values():
#             folder2_unique.append(filename)
#
#     return folder1_unique, folder2_unique
#
#
# def main():
#     folder1_path = '/home/liudd/data/fy4a_clm'
#     folder2_path = '/home/liudd/data/fy4a_clt'
#
#     folder1_identifiers = get_file_identifiers(folder1_path)
#     folder2_identifiers = get_file_identifiers(folder2_path)
#
#     folder1_unique, folder2_unique = compare_file_identifiers(folder1_identifiers, folder2_identifiers)
#
#     if folder1_unique:
#         print("在文件夹1中独有的文件:")
#         for filename in folder1_unique:
#             print(filename)
#     else:
#         print("文件夹1中没有独有的文件。")
#
#     if folder2_unique:
#         print("在文件夹2中独有的文件:")
#         for filename in folder2_unique:
#             print(filename)
#     else:
#         print("文件夹2中没有独有的文件。")
#
#
# if __name__ == '__main__':
#     main()

# 2、nc和HDF间比较
import os


def get_file_identifiers(folder_path, extensions):
    """提取文件夹中所有文件名的特定部分"""
    file_identifiers = {}
    for filename in os.listdir(folder_path):
        if any(filename.endswith(ext) for ext in extensions):
            parts = filename.split('_')
            if len(parts) > 10:  # 确保文件名分割后有足够的部分
                identifier = '_'.join(parts[9:11])
                file_identifiers[filename] = identifier
            else:
                print(f"文件名格式错误: {filename}")
    return file_identifiers


def compare_file_identifiers(folder1_identifiers, folder2_identifiers):
    """比较两个文件夹的文件名特定部分"""
    folder1_unique = []
    folder2_unique = []

    for filename, identifier in folder1_identifiers.items():
        if identifier not in folder2_identifiers.values():
            folder1_unique.append(filename)

    for filename, identifier in folder2_identifiers.items():
        if identifier not in folder1_identifiers.values():
            folder2_unique.append(filename)

    return folder1_unique, folder2_unique


def main():
    folder1_path = '/mnt/space1/liudddata/fy_L1'
    folder2_path = '/mnt/space1/liudddata/fy_ctt_9_12'
    extensions = ['.HDF', '.NC']

    folder1_identifiers = get_file_identifiers(folder1_path, extensions)
    folder2_identifiers = get_file_identifiers(folder2_path, extensions)

    folder1_unique, folder2_unique = compare_file_identifiers(folder1_identifiers, folder2_identifiers)

    if folder1_unique:
        print("在文件夹1中独有的文件:")
        for filename in folder1_unique:
            print(filename)
    else:
        print("文件夹1中没有独有的文件。")

    if folder2_unique:
        print("在文件夹2中独有的文件:")
        for filename in folder2_unique:
            print(filename)
    else:
        print("文件夹2中没有独有的文件。")


if __name__ == '__main__':
    main()

# # 3、找出多出的
# import os
#
#
# def get_file_identifiers(folder_path, extensions):
#     """提取文件夹中所有文件名的特定部分"""
#     file_identifiers = {}
#     for filename in os.listdir(folder_path):
#         if any(filename.endswith(ext) for ext in extensions):
#             parts = filename.split('_')
#             if len(parts) > 11:  # 确保文件名分割后有足够的部分
#                 identifier = '_'.join(parts[9:11])
#                 file_identifiers[filename] = identifier
#             else:
#                 print(f"文件名格式错误: {filename}")
#     return file_identifiers
#
#
# def compare_file_identifiers(folder1_identifiers, folder2_identifiers):
#     """比较两个文件夹的文件名特定部分"""
#     folder1_unique = []
#     folder2_unique = []
#
#     for filename, identifier in folder1_identifiers.items():
#         if identifier not in folder2_identifiers.values():
#             folder1_unique.append(filename)
#
#     for filename, identifier in folder2_identifiers.items():
#         if identifier not in folder1_identifiers.values():
#             folder2_unique.append(filename)
#
#     return folder1_unique, folder2_unique
#
#
# def main():
#     folder1_path = '/mnt/space2/liudd/fy4aL1'
#     folder2_path = '/home/liudd/data/fy4a_clt'
#     extensions = ['.HDF', '.NC']
#
#     folder1_identifiers = get_file_identifiers(folder1_path, extensions)
#     folder2_identifiers = get_file_identifiers(folder2_path, extensions)
#
#     print("文件夹1标识符:")
#     for filename, identifier in folder1_identifiers.items():
#         print(f"{filename}: {identifier}")
#
#     print("\n文件夹2标识符:")
#     for filename, identifier in folder2_identifiers.items():
#         print(f"{filename}: {identifier}")
#
#     folder1_unique, folder2_unique = compare_file_identifiers(folder1_identifiers, folder2_identifiers)
#
#     if folder1_unique:
#         print("在文件夹1中独有的文件:")
#         for filename in folder1_unique:
#             print(filename)
#     else:
#         print("文件夹1中没有独有的文件。")
#
#     if folder2_unique:
#         print("在文件夹2中独有的文件:")
#         for filename in folder2_unique:
#             print(filename)
#     else:
#         print("文件夹2中没有独有的文件。")
#
#
# if __name__ == '__main__':
#     main()
#
